#coding: utf-8
from __future__ import unicode_literals

from django.db import models


from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class MyClass(object):
    def __str__(self):
        return "Instance of my class"

class Categroy(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=20)
    summary = models.CharField(max_length=50)
    status = models.IntegerField()
    remark = models.CharField(max_length=50, blank=True, null=True)
    create_user = models.IntegerField()
    create_time = models.DateTimeField()
    update_user = models.IntegerField()
    update_time = models.DateTimeField()

    def getattrs(self,args=[]):
        '''
        获取文档的基本属性，如果指定属性，将返回对象指定的属性，否则返回所有属性，
        :param args: 属性列表
        :return: 返回包含属性的字典
        '''

        attrs = vars(self)
        attrs['create_time'] = str(self.create_time)
        attrs['update_time'] = str(self.update_time)#先处理再过滤 因为字典里添加和修改做同样的动作 若写在if里面 易造成添加属性的操作
        del attrs['_state']#_state
        if args:
            attrs = {arg:attrs.get(arg) for arg in args}
        return  attrs

    def __unicode__(self):
        return self.name




    class Meta:
        managed = True
        db_table = 'categroy'


class Section(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=20)
    summary = models.CharField(max_length=50)
    videos_id = models.IntegerField()
    teachar_id = models.IntegerField()
    url = models.CharField(max_length=100)
    cover = models.CharField(max_length=100)
    hit = models.CharField(max_length=100)
    status = models.IntegerField()
    remark = models.CharField(max_length=50, blank=True, null=True)
    create_user = models.IntegerField()
    create_time = models.DateTimeField()
    update_user = models.IntegerField()
    update_time = models.DateTimeField()

    class Meta:
        managed = True
        db_table = 'section'


class Video(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=20)
    summary = models.CharField(max_length=50)
    category_id = models.IntegerField()
    status = models.IntegerField()
    remark = models.CharField(max_length=50, blank=True, null=True)
    create_user = models.IntegerField()
    create_time = models.DateTimeField()
    update_user = models.IntegerField()
    uodate_time = models.DateTimeField()

    class Meta:
        managed = True
        db_table = 'video'
